<?php
/**
 * Created by 七月
 * User: 七月
 * Date: 2017/2/15
 * Time: 13:40
 */

namespace app\api\controller\v1;


use app\api\controller\BaseController;
use app\api\validate\IDMustBePositiveInt;
use app\api\model\Activity as ActivityModel;
use app\lib\exception\MissException;

class Activity extends BaseController
{

    public function getActivity($id)
    {
        $validate = new IDMustBePositiveInt();
        $validate->goCheck();
        $activity = ActivityModel::getActivityById($id);
        if (!$activity ) {
            throw new MissException([
                'msg' => '请求banner不存在',
                'errorCode' => 40000
            ]);
        }
        return $activity;
    }

    public function getByUid($id)
    {
        $validate = new IDMustBePositiveInt();
        $validate->goCheck();
        $activityModel = new ActivityModel;
        $paging = $activityModel->getByUid($id, true, 1, 20);

        if ($paging->isEmpty())
        {

            return [
                'current_page' => $paging->currentPage(),
                'data' => []
            ];
        }

        $data = $paging
            ->toArray();

        return json([
            'current_page' => $paging->currentPage(),
            'data' => $data
        ]);
    }
}